<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="third/main.css">
		<script src="./index/jquery.js" type="text/javaScript"></script>
		<title>详情</title>
	<!-- 	<script type="text/javascript" src="./lib/kkpager.min.js"></script>
		<link rel="stylesheet" type="text/css" href="./lib/kkpager_blue.css" /> -->
		<style>

		</style>
	</head>
	<body>
		<header class="YMH2019_New_home_hd">
			<div class="home_top">
				<div class="YMH2019_New_main Z_clearfix">
					<div class="main_logo"></div>
					<a href="./index.html">
						<div class="logo"></div>
					</a>
				</div>
			</div>
		</header>
		<div class="list">
			<ul class="categary"></ul>
			<div id="page" class="page_div"></div>
		</div>
	</body>
	<script src="./lib/pageMe.js"></script>
	<script>
		function getParameter(name) {
			var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
			var r = window.location.search.substr(1).match(reg); 
			if (r!=null) return unescape(r[2]); return null;
		}
		
		function getUrlParams(key) {
			var url = window.location.search.substr(1);
			if (url == '') {
				return false;
			}
			var paramsArr = url.split('&');
			for (var i = 0; i < paramsArr.length; i++) {
				var combina = paramsArr[i].split("=");
				if (combina[0] == key) {
					return combina[1];
				}
			}
			return false;
		}
		$(()=>{
			const id = getUrlParams('id')
			function getList(page) {
				// var current = 1;
				// var totalPage = 0;
				// var totalRecords = 0;
				
				$.ajax({
				   url:"http://tushu.hnjixuanyun.cn/api/books/books",
					type:"POST",
					data:{'category_id':id,page}, 
					success:function (data) {
						if(data.data.data.length==0){
							$('.categary').html('<div style="font-size: 20px;color: #aaa;text-align: center;padding: 100px;">暂无资料~</div>')
						}
						if(page==1){
							initPage(page,data.data.last_page,data.data.total)
						}
						
						data.data.data.map(item=>{
						   const li = `
							<li>
								<a href="${item.images}" target='blank'>
									${item.title}
								</a>
							</li>`
							$('.categary').append(li)
					   })
					},
					error:function () {
					   alert("出错了...")
					}
				});
			}
			getList(1)
			
			function initPage(pno,total,totalRecords){
				console.log(pno,total,totalRecords)
				// kkpager.generPageHtml({
				// 	pno,
				// 	total,
				// 	totalRecords,
				// 	mode : 'click',
				// 	click : function(n){
				// 		$('.categary').empty()
				// 		getList(n);
				// 	}
				// });
				$("#page").paging({
					pageNum: pno, // 当前页面
					totalNum: total, // 总页码
					totalList: totalRecords, // 记录总数量
					callback: function (n) { //回调函数
						$('.categary').empty()
						getList(n);
					}
				});
		}
		})
	</script>

</html>